function KDE_bounds_par
% boundary effects correction for kernel density estiamtes

boundsfig=figure( ...
   'Visible','on', ...
   'Name','Data Saving', ...
   'Units','Normalized',...
   'Tag','KDE_BOUNDS',...
   'NumberTitle','off');

mf=findobj('Tag','KDE_MAIN');udata=get(mf,'UserData');
bounds=udata.bounds;
if length(bounds)<2
 X=udata.X;
 bounds=[min(X),max(X)];
end
lbs=num2str(bounds(1));
rbs=num2str(bounds(2));

% Title
uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.8,.8,.1], ...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.5,...
        'String','Parameters for boundary effects correction');

% Left boundary
uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.55,.4,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Left boundary:');

% edit fields
uicontrol( ...
        'Style','edit', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.35,.59,.15,.065], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.9 0.9 0.9], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'Tag','KDE_BOUNDS_L',...
        'String',lbs);

% min of data
uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.55,.59,.25,.065], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.9 0.9 0.9], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'Tag','KDE_BOUNDS_MIN',...
        'String','Use minimum of data', ...
        'Callback','bl=findobj(''Tag'',''KDE_BOUNDS_L'');mf=findobj(''Tag'',''KDE_MAIN'');udata=get(mf,''UserData'');X=udata.X;minX=min(X);lbs=num2str(minX);set(bl,''String'',lbs);bounds=udata.bounds;bounds(1)=minX;udata.bounds=bounds;set(mf,''UserData'',udata);');

% Right boundary
uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.1,.25,.4,.1], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.8 0.8 0.8], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'String','Right boundary:');

% edit fields
uicontrol( ...
        'Style','edit', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.35,.29,.15,.065], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.9 0.9 0.9], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'Tag','KDE_BOUNDS_R',...
        'String',rbs);

% max of data
uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[.55,.29,.25,.065], ...
        'HorizontalAlignment','left',...
        'BackgroundColor',[0.9 0.9 0.9], ...
        'ForegroundColor',[0 0 0], ...
        'FontSize',0.4,...
        'Tag','KDE_BOUNDS_MAX',...
        'String','Use maximum of data', ...
        'Callback','br=findobj(''Tag'',''KDE_BOUNDS_R'');mf=findobj(''Tag'',''KDE_MAIN'');udata=get(mf,''UserData'');X=udata.X;maxX=max(X);rbs=num2str(maxX);set(br,''String'',rbs);bounds=udata.bounds;bounds(2)=maxX;udata.bounds=bounds;set(mf,''UserData'',udata);');


% Apply button
uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.1,0.05,.15,0.05], ...
        'String','Apply', ...
        'Callback','bl=findobj(''Tag'',''KDE_BOUNDS_L'');br=findobj(''Tag'',''KDE_BOUNDS_R'');lbs=get(bl,''String'');rbs=get(br,''String'');mf=findobj(''Tag'',''KDE_MAIN'');udata=get(mf,''UserData'');bounds=[str2num(lbs),str2num(rbs)];udata.bounds=bounds;set(mf,''UserData'',udata);close(gcf)');

% Close button
uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'FontUnits','normalized',...
        'Position',[0.8,0.05,.15,0.05], ...
        'String','Cancel', ...
        'Callback','close(gcf)');

set(boundsfig,'Position',[0.10 0.15 0.500 0.5]);
